-
Notifications
You must be signed in to change notification settings - Fork 745
/
AspNetMembershipProvider.cs
1699 lines (1495 loc) · 64.4 KB
/
AspNetMembershipProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Security.Membership
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration.Provider;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Entities.Host;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Entities.Users;
using DotNetNuke.Entities.Users.Membership;
using DotNetNuke.Entities.Users.Social;
using DotNetNuke.Instrumentation;
using DotNetNuke.Internal.SourceGenerators;
using DotNetNuke.Services.Exceptions;
// DNN-4016
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Log.EventLog;
/// <summary>The AspNetMembershipProvider overrides the default MembershipProvider to provide an AspNet Membership Component (MemberRole) implementation.</summary>
public partial class AspNetMembershipProvider : MembershipProvider
{
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(AspNetMembershipProvider));
private static Random random = new Random();
private readonly DataProvider dataProvider = DataProvider.Instance();
private readonly IEnumerable<string> socialAuthProviders = new List<string>() { "Facebook", "Google", "Twitter", "LiveID" };
/// <inheritdoc/>
public override bool CanEditProviderProperties
{
get { return false; }
}
/// <inheritdoc/>
public override int MaxInvalidPasswordAttempts
{
get
{
return System.Web.Security.Membership.MaxInvalidPasswordAttempts;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override int MinNonAlphanumericCharacters
{
get
{
return System.Web.Security.Membership.MinRequiredNonAlphanumericCharacters;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override int MinPasswordLength
{
get
{
return System.Web.Security.Membership.MinRequiredPasswordLength;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override int PasswordAttemptWindow
{
get
{
return System.Web.Security.Membership.PasswordAttemptWindow;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override PasswordFormat PasswordFormat
{
get
{
switch (System.Web.Security.Membership.Provider.PasswordFormat)
{
case MembershipPasswordFormat.Encrypted:
return PasswordFormat.Encrypted;
case MembershipPasswordFormat.Hashed:
return PasswordFormat.Hashed;
default:
return PasswordFormat.Clear;
}
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override bool PasswordResetEnabled
{
get
{
return System.Web.Security.Membership.EnablePasswordReset;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override bool PasswordRetrievalEnabled
{
get
{
return System.Web.Security.Membership.EnablePasswordRetrieval;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override string PasswordStrengthRegularExpression
{
get
{
return System.Web.Security.Membership.PasswordStrengthRegularExpression;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override bool RequiresQuestionAndAnswer
{
get
{
return System.Web.Security.Membership.RequiresQuestionAndAnswer;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
/// <inheritdoc/>
public override bool RequiresUniqueEmail
{
get
{
return System.Web.Security.Membership.Provider.RequiresUniqueEmail;
}
set
{
throw new NotSupportedException(
"Provider properties for AspNetMembershipProvider must be set in web.config");
}
}
public static ArrayList FillUserCollection(int portalId, IDataReader dr)
{
// Note: the DataReader returned from this method should contain 2 result sets. The first set
// contains the TotalRecords, that satisfy the filter, the second contains the page
// of data
var arrUsers = new ArrayList();
try
{
while (dr.Read())
{
// fill business object
UserInfo user = FillUserInfo(portalId, dr, false);
// add to collection
arrUsers.Add(user);
}
}
catch (Exception exc)
{
Exceptions.LogException(exc);
}
finally
{
// close datareader
CBO.CloseDataReader(dr, true);
}
return arrUsers;
}
/// <inheritdoc/>
public override UserInfo GetUserByAuthToken(int portalId, string userToken, string authType)
{
IDataReader dr = this.dataProvider.GetUserByAuthToken(portalId, userToken, authType);
UserInfo objUserInfo = FillUserInfo(portalId, dr, true);
return objUserInfo;
}
/// <inheritdoc />
public override void AddUserPortal(int portalId, int userId)
{
Requires.NotNullOrEmpty("portalId", portalId.ToString());
Requires.NotNullOrEmpty("userId", userId.ToString());
this.dataProvider.AddUserPortal(portalId, userId);
}
/// <inheritdoc />
public override void ChangeUsername(int userId, string newUsername)
{
Requires.NotNull("userId", userId);
Requires.NotNullOrEmpty("newUsername", newUsername);
var userName = PortalSecurity.Instance.InputFilter(
newUsername,
PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoAngleBrackets | PortalSecurity.FilterFlag.NoMarkup);
if (!userName.Equals(newUsername))
{
throw new ArgumentException(Localization.GetExceptionMessage("InvalidUserName", "The username specified is invalid."));
}
var valid = UserController.Instance.IsValidUserName(userName);
if (!valid)
{
throw new ArgumentException(Localization.GetExceptionMessage("InvalidUserName", "The username specified is invalid."));
}
// read all the user account settings
var portalSettings = PortalController.Instance.GetCurrentPortalSettings();
if (portalSettings != null)
{
var settings = UserController.GetUserSettings(portalSettings.PortalId);
// User Name Validation
var userNameValidator = this.GetStringSetting(settings, "Security_UserNameValidation");
if (!string.IsNullOrEmpty(userNameValidator))
{
var regExp = RegexUtils.GetCachedRegex(userNameValidator, RegexOptions.IgnoreCase | RegexOptions.Multiline);
var matches = regExp.Matches(userName);
if (matches.Count == 0)
{
throw new ArgumentException(Localization.GetExceptionMessage("InvalidUserName", "The username specified is invalid."));
}
}
}
this.dataProvider.ChangeUsername(userId, userName);
EventLogController.Instance.AddLog(
"userId",
userId.ToString(),
portalSettings,
UserController.Instance.GetCurrentUserInfo().UserID,
EventLogController.EventLogType.USERNAME_UPDATED);
DataCache.ClearCache();
}
/// <inheritdoc />
public override bool ChangePassword(UserInfo user, string oldPassword, string newPassword)
{
MembershipUser aspnetUser = GetMembershipUser(user);
var m = new MembershipPasswordController();
if (m.IsPasswordInHistory(user.UserID, user.PortalID, newPassword))
{
return false;
}
if (string.IsNullOrEmpty(oldPassword))
{
aspnetUser.UnlockUser();
oldPassword = aspnetUser.GetPassword();
}
bool retValue = aspnetUser.ChangePassword(oldPassword, newPassword);
if (retValue && this.PasswordRetrievalEnabled && !this.RequiresQuestionAndAnswer)
{
string confirmPassword = aspnetUser.GetPassword();
if (confirmPassword == newPassword)
{
user.Membership.Password = confirmPassword;
}
else
{
retValue = false;
}
}
return retValue;
}
/// <inheritdoc />
public override bool ChangePasswordQuestionAndAnswer(UserInfo user, string password, string passwordQuestion, string passwordAnswer)
{
MembershipUser aspnetUser = GetMembershipUser(user);
if (password == Null.NullString)
{
password = aspnetUser.GetPassword();
}
return aspnetUser.ChangePasswordQuestionAndAnswer(password, passwordQuestion, passwordAnswer);
}
/// <inheritdoc />
public override UserCreateStatus CreateUser(ref UserInfo user)
{
UserCreateStatus createStatus = this.ValidateForProfanity(user);
string service = HttpContext.Current != null ? HttpContext.Current.Request.Params["state"] : string.Empty;
if (createStatus == UserCreateStatus.AddUser)
{
this.ValidateForDuplicateDisplayName(user, ref createStatus);
}
if (createStatus == UserCreateStatus.AddUser)
{
try
{
// check if username exists in database for any portal
UserInfo objVerifyUser = this.GetUserByUserName(Null.NullInteger, user.Username);
if (objVerifyUser != null)
{
// DNN-4016
// the username exists so we should now verify the password, DNN-4016 or check for oauth user authentication.
if (ValidateUser(user.Username, user.Membership.Password))
{
// check if user exists for the portal specified
objVerifyUser = this.GetUserByUserName(user.PortalID, user.Username);
if (objVerifyUser != null)
{
if (objVerifyUser.PortalID == user.PortalID && (!user.IsSuperUser || user.PortalID == Null.NullInteger))
{
createStatus = UserCreateStatus.UserAlreadyRegistered;
}
else
{
// SuperUser who is not part of portal
createStatus = UserCreateStatus.AddUserToPortal;
}
}
else
{
createStatus = UserCreateStatus.AddUserToPortal;
}
}
else
{
// not the same person - prevent registration
createStatus = UserCreateStatus.UsernameAlreadyExists;
}
}
else
{
// the user does not exist
createStatus = UserCreateStatus.AddUser;
}
// If new user - add to aspnet membership
if (createStatus == UserCreateStatus.AddUser)
{
createStatus = CreateMemberhipUser(user);
}
// If asp user has been successfully created or we are adding a existing user
// to a new portal
if (createStatus == UserCreateStatus.Success || createStatus == UserCreateStatus.AddUserToPortal)
{
// Create the DNN User Record
createStatus = this.CreateDNNUser(ref user);
if (createStatus == UserCreateStatus.Success)
{
// Persist the Profile to the Data Store
ProfileController.UpdateUserProfile(user);
}
}
}
catch (Exception exc)
{
// an unexpected error occurred
Exceptions.LogException(exc);
createStatus = UserCreateStatus.UnexpectedError;
}
}
return createStatus;
}
/// <inheritdoc />
public override bool DeleteUser(UserInfo user)
{
bool retValue = true;
try
{
this.dataProvider.DeleteUserFromPortal(user.UserID, user.PortalID);
}
catch (Exception ex)
{
Exceptions.LogException(ex);
retValue = false;
}
return retValue;
}
/// <inheritdoc />
[DnnDeprecated(8, 0, 0, "Other solutions exist outside of the DNN Platform", RemovalVersion = 11)]
public override partial void DeleteUsersOnline(int timeWindow)
{
this.dataProvider.DeleteUsersOnline(timeWindow);
}
/// <inheritdoc />
public override string GeneratePassword()
{
return this.GeneratePassword(this.MinPasswordLength + 4);
}
/// <inheritdoc />
public override string GeneratePassword(int length)
{
return System.Web.Security.Membership.GeneratePassword(length, this.MinNonAlphanumericCharacters);
}
/// <inheritdoc/>
public override ArrayList GetDeletedUsers(int portalId)
{
return FillUserCollection(portalId, this.dataProvider.GetDeletedUsers(portalId));
}
/// <inheritdoc />
[DnnDeprecated(8, 0, 0, "Other solutions exist outside of the DNN Platform", RemovalVersion = 11)]
public override partial ArrayList GetOnlineUsers(int portalId)
{
int totalRecords = 0;
return FillUserCollection(portalId, this.dataProvider.GetOnlineUsers(portalId), ref totalRecords);
}
/// <inheritdoc />
public override string GetPassword(UserInfo user, string passwordAnswer)
{
MembershipUser aspnetUser = GetMembershipUser(user);
if (aspnetUser.IsLockedOut)
{
AutoUnlockUser(aspnetUser);
}
return this.RequiresQuestionAndAnswer ? aspnetUser.GetPassword(passwordAnswer) : aspnetUser.GetPassword();
}
/// <inheritdoc/>
public override ArrayList GetUnAuthorizedUsers(int portalId)
{
return this.GetUnAuthorizedUsers(portalId, false, false);
}
/// <inheritdoc/>
public override ArrayList GetUnAuthorizedUsers(int portalId, bool includeDeleted, bool superUsersOnly)
{
return FillUserCollection(
portalId,
this.dataProvider.GetUnAuthorizedUsers(portalId, includeDeleted, superUsersOnly));
}
/// <inheritdoc />
public override UserInfo GetUser(int portalId, int userId)
{
IDataReader dr = this.dataProvider.GetUser(portalId, userId);
UserInfo objUserInfo = FillUserInfo(portalId, dr, true);
return objUserInfo;
}
/// <inheritdoc />
public override UserInfo GetUserByDisplayName(int portalId, string displayName)
{
IDataReader dr = this.dataProvider.GetUserByDisplayName(portalId, displayName);
UserInfo objUserInfo = FillUserInfo(portalId, dr, true);
return objUserInfo;
}
/// <inheritdoc />
public override UserInfo GetUserByUserName(int portalId, string username)
{
return CBO.GetCachedObject<UserInfo>(
new CacheItemArgs(
string.Format(DataCache.UserCacheKey, portalId, username),
DataCache.UserCacheTimeOut,
DataCache.UserCachePriority),
_ => this.GetUserByUserNameFromDataStore(portalId, username));
}
/// <inheritdoc />
public override UserInfo GetUserByVanityUrl(int portalId, string vanityUrl)
{
UserInfo user = null;
if (!string.IsNullOrEmpty(vanityUrl))
{
IDataReader dr = this.dataProvider.GetUserByVanityUrl(portalId, vanityUrl);
user = FillUserInfo(portalId, dr, true);
}
return user;
}
/// <inheritdoc />
public override UserInfo GetUserByPasswordResetToken(int portalId, string resetToken)
{
UserInfo user = null;
if (!string.IsNullOrEmpty(resetToken))
{
IDataReader dr = this.dataProvider.GetUserByPasswordResetToken(portalId, resetToken);
user = FillUserInfo(portalId, dr, true);
}
return user;
}
/// <inheritdoc/>
public override string GetProviderUserKey(UserInfo user)
{
return GetMembershipUser(user).ProviderUserKey?.ToString().Replace("-", string.Empty) ?? string.Empty;
}
/// <inheritdoc/>
public override UserInfo GetUserByProviderUserKey(int portalId, string providerUserKey)
{
var userName = GetMembershipUserByUserKey(providerUserKey)?.UserName ?? string.Empty;
if (string.IsNullOrEmpty(userName))
{
return null;
}
return this.GetUserByUserName(portalId, userName);
}
/// <inheritdoc />
public override int GetUserCountByPortal(int portalId)
{
return this.dataProvider.GetUserCountByPortal(portalId);
}
/// <inheritdoc />
public override void GetUserMembership(ref UserInfo user)
{
// Get AspNet MembershipUser
MembershipUser aspnetUser = GetMembershipUser(user);
// Fill Membership Property
FillUserMembership(aspnetUser, user);
// Get Online Status
user.Membership.IsOnLine = this.IsUserOnline(user);
}
/// <inheritdoc />
public override ArrayList GetUsers(int portalId, int pageIndex, int pageSize, ref int totalRecords)
{
return this.GetUsers(portalId, pageIndex, pageSize, ref totalRecords, false, false);
}
/// <inheritdoc />
public override ArrayList GetUsers(int portalId, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
{
if (pageIndex == -1)
{
pageIndex = 0;
pageSize = int.MaxValue;
}
return FillUserCollection(
portalId,
this.dataProvider.GetAllUsers(
portalId,
pageIndex,
pageSize,
includeDeleted,
superUsersOnly),
ref totalRecords);
}
/// <inheritdoc/>
public override IList<UserInfo> GetUsersAdvancedSearch(int portalId, int userId, int filterUserId, int filterRoleId, int relationshipTypeId, bool isAdmin, int pageIndex, int pageSize, string sortColumn, bool sortAscending, string propertyNames, string propertyValues)
{
return FillUserList(
portalId,
this.dataProvider.GetUsersAdvancedSearch(
portalId,
userId,
filterUserId,
filterRoleId,
relationshipTypeId,
isAdmin,
pageIndex,
pageSize,
sortColumn,
sortAscending,
propertyNames,
propertyValues));
}
/// <inheritdoc/>
public override IList<UserInfo> GetUsersBasicSearch(int portalId, int pageIndex, int pageSize, string sortColumn, bool sortAscending, string propertyName, string propertyValue)
{
return FillUserList(
portalId,
this.dataProvider.GetUsersBasicSearch(
portalId,
pageIndex,
pageSize,
sortColumn,
sortAscending,
propertyName,
propertyValue));
}
/// <inheritdoc />
public override ArrayList GetUsersByEmail(int portalId, string emailToMatch, int pageIndex, int pageSize, ref int totalRecords)
{
return this.GetUsersByEmail(portalId, emailToMatch, pageIndex, pageSize, ref totalRecords, false, false);
}
/// <inheritdoc />
public override ArrayList GetUsersByEmail(int portalId, string emailToMatch, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
{
if (pageIndex == -1)
{
pageIndex = 0;
pageSize = int.MaxValue;
}
return FillUserCollection(
portalId,
this.dataProvider.GetUsersByEmail(
portalId,
emailToMatch,
pageIndex,
pageSize,
includeDeleted,
superUsersOnly),
ref totalRecords);
}
/// <inheritdoc />
public override ArrayList GetUsersByUserName(int portalId, string userNameToMatch, int pageIndex, int pageSize, ref int totalRecords)
{
return this.GetUsersByUserName(portalId, userNameToMatch, pageIndex, pageSize, ref totalRecords, false, false);
}
/// <inheritdoc />
public override ArrayList GetUsersByUserName(int portalId, string userNameToMatch, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
{
if (pageIndex == -1)
{
pageIndex = 0;
pageSize = int.MaxValue;
}
return FillUserCollection(
portalId,
this.dataProvider.GetUsersByUsername(
portalId,
userNameToMatch,
pageIndex,
pageSize,
includeDeleted,
superUsersOnly),
ref totalRecords);
}
/// <inheritdoc />
public override ArrayList GetUsersByDisplayName(int portalId, string nameToMatch, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
{
if (pageIndex == -1)
{
pageIndex = 0;
pageSize = int.MaxValue;
}
return FillUserCollection(
portalId,
this.dataProvider.GetUsersByDisplayname(
portalId,
nameToMatch,
pageIndex,
pageSize,
includeDeleted,
superUsersOnly),
ref totalRecords);
}
/// <inheritdoc />
public override ArrayList GetUsersByProfileProperty(int portalId, string propertyName, string propertyValue, int pageIndex, int pageSize, ref int totalRecords)
{
return this.GetUsersByProfileProperty(
portalId,
propertyName,
propertyValue,
pageIndex,
pageSize,
ref totalRecords,
false,
false);
}
/// <inheritdoc />
public override ArrayList GetUsersByProfileProperty(int portalId, string propertyName, string propertyValue, int pageIndex, int pageSize, ref int totalRecords, bool includeDeleted, bool superUsersOnly)
{
if (pageIndex == -1)
{
pageIndex = 0;
pageSize = int.MaxValue;
}
return FillUserCollection(
portalId,
this.dataProvider.GetUsersByProfileProperty(
portalId,
propertyName,
propertyValue,
pageIndex,
pageSize,
includeDeleted,
superUsersOnly),
ref totalRecords);
}
/// <inheritdoc />
[DnnDeprecated(8, 0, 0, "Other solutions exist outside of the DNN Platform", RemovalVersion = 11)]
public override partial bool IsUserOnline(UserInfo user)
{
bool isOnline = false;
var objUsersOnline = new UserOnlineController();
if (objUsersOnline.IsEnabled())
{
Hashtable userList = objUsersOnline.GetUserList();
var onlineUser = (OnlineUserInfo)userList[user.UserID.ToString()];
if (onlineUser != null)
{
isOnline = true;
}
else
{
// Next try the Database
onlineUser = CBO.FillObject<OnlineUserInfo>(this.dataProvider.GetOnlineUser(user.UserID));
if (onlineUser != null)
{
isOnline = true;
}
}
}
return isOnline;
}
/// <inheritdoc/>
public override bool RemoveUser(UserInfo user)
{
bool retValue = true;
try
{
foreach (var relationship in user.Social.UserRelationships)
{
RelationshipController.Instance.DeleteUserRelationship(relationship);
}
this.dataProvider.RemoveUser(user.UserID, user.PortalID);
// Prior to removing membership, ensure user is not present in any other portal
UserInfo otherUser = this.GetUserByUserNameFromDataStore(Null.NullInteger, user.Username);
if (otherUser == null)
{
DeleteMembershipUser(user);
}
}
catch (Exception ex)
{
Exceptions.LogException(ex);
retValue = false;
}
return retValue;
}
/// <inheritdoc />
public override string ResetPassword(UserInfo user, string passwordAnswer)
{
// Get AspNet MembershipUser
MembershipUser aspnetUser = GetMembershipUser(user);
return this.RequiresQuestionAndAnswer ? aspnetUser.ResetPassword(passwordAnswer) : aspnetUser.ResetPassword();
}
/// <inheritdoc />
public override bool ResetAndChangePassword(UserInfo user, string newPassword)
{
return this.ResetAndChangePassword(user, newPassword, string.Empty);
}
/// <inheritdoc/>
public override bool ResetAndChangePassword(UserInfo user, string newPassword, string answer)
{
if (this.RequiresQuestionAndAnswer && string.IsNullOrEmpty(answer))
{
return false;
}
// Get AspNet MembershipUser
MembershipUser aspnetUser = GetMembershipUser(user);
if (aspnetUser.IsLockedOut)
{
aspnetUser.UnlockUser();
}
string resetPassword = this.ResetPassword(user, answer);
return aspnetUser.ChangePassword(resetPassword, newPassword);
}
/// <inheritdoc/>
public override bool RestoreUser(UserInfo user)
{
bool retValue = true;
try
{
this.dataProvider.RestoreUser(user.UserID, user.PortalID);
}
catch (Exception ex)
{
Exceptions.LogException(ex);
retValue = false;
}
return retValue;
}
/// <inheritdoc />
public override bool UnLockUser(UserInfo user)
{
MembershipUser membershipUser = System.Web.Security.Membership.GetUser(user.Username);
bool retValue = false;
if (membershipUser != null)
{
retValue = membershipUser.UnlockUser();
}
DataCache.RemoveCache(GetCacheKey(user.Username));
return retValue;
}
/// <inheritdoc />
public override void UserAgreedToTerms(UserInfo user)
{
this.dataProvider.UserAgreedToTerms(PortalController.GetEffectivePortalId(user.PortalID), user.UserID);
}
/// <inheritdoc />
public override void ResetTermsAgreement(int portalId)
{
this.dataProvider.ResetTermsAgreement(portalId);
}
/// <inheritdoc />
public override void UserRequestsRemoval(UserInfo user, bool remove)
{
this.dataProvider.UserRequestsRemoval(user.PortalID, user.UserID, remove);
}
/// <inheritdoc />
public override void UpdateUser(UserInfo user)
{
var objSecurity = PortalSecurity.Instance;
string firstName = objSecurity.InputFilter(
user.FirstName,
PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoAngleBrackets | PortalSecurity.FilterFlag.NoMarkup);
string lastName = objSecurity.InputFilter(
user.LastName,
PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoAngleBrackets | PortalSecurity.FilterFlag.NoMarkup);
string email = objSecurity.InputFilter(
user.Email,
PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoAngleBrackets | PortalSecurity.FilterFlag.NoMarkup);
string displayName = objSecurity.InputFilter(
user.DisplayName,
PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoAngleBrackets | PortalSecurity.FilterFlag.NoMarkup);
if (displayName.Contains("<"))
{
displayName = HttpUtility.HtmlEncode(displayName);
}
if (!firstName.Equals(user.FirstName))
{
user.FirstName = firstName;
}
if (!lastName.Equals(user.LastName))
{
user.LastName = lastName;
}
bool updatePassword = user.Membership.UpdatePassword;
bool isApproved = user.Membership.Approved;
if (string.IsNullOrEmpty(displayName))
{
displayName = firstName + " " + lastName;
}
// Persist the Membership to the Data Store
UpdateUserMembership(user);
// Persist the DNN User to the Database
this.dataProvider.UpdateUser(
user.UserID,
user.PortalID,
firstName,
lastName,
user.IsSuperUser,
email,
displayName,
user.VanityUrl,
updatePassword,
isApproved,
false,
user.LastIPAddress,
user.PasswordResetToken,
user.PasswordResetExpiration,
user.IsDeleted,
UserController.Instance.GetCurrentUserInfo().UserID);
// Persist the Profile to the Data Store
ProfileController.UpdateUserProfile(user);
}
/// <inheritdoc />
[DnnDeprecated(8, 0, 0, "Other solutions exist outside of the DNN Platform", RemovalVersion = 11)]
public override partial void UpdateUsersOnline(Hashtable userList)
{
this.dataProvider.UpdateUsersOnline(userList);
}
/// <inheritdoc />
public override UserInfo UserLogin(int portalId, string username, string password, string verificationCode, ref UserLoginStatus loginStatus)
{
return this.UserLogin(portalId, username, password, "DNN", verificationCode, ref loginStatus);
}
/// <inheritdoc />
public override UserInfo UserLogin(int portalId, string username, string password, string authType, string verificationCode, ref UserLoginStatus loginStatus)
{
// For now, we are going to ignore the possibility that the User may exist in the
// Global Data Store but not in the Local DataStore ie. A shared Global Data Store
// Initialise Login Status to Failure
loginStatus = UserLoginStatus.LOGIN_FAILURE;